package com.xqt.dao.sys;


import com.xqt.base.dao.BaseDao;
import com.xqt.base.entity.BaseEntity;
import com.xqt.base.page.BasePage;
import com.xqt.entity.sys.SysRole;
import com.xqt.entity.sys.SysRoleMember;
import com.xqt.entity.sys.SysRoleMenu;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 菜单基础表Dao
 * 
 * @author 梁华
 *
 */
@Repository
public class SysRoleDao extends BaseDao<SysRole> {

    @Override
    public String getReadSql() {
        return "read.sysrole.";
    }

    @Override
    public String getWriteSql() {
        return "write.sysrole.";
    }

    /**
     * 根据code查询角色
     *
     * @param code
     * @return
     */
    public SysRole queryByCode(Object code){
       return readSqlSession.selectOne(getReadSql()+"queryByCode",code);
    }

    /**
     * 检测角色是否存在
     *
     * @param page
     * @return
     */
    public int checkRoleExist(BaseEntity page){
        return readSqlSession.selectOne(getReadSql()+"checkRoleExist",page);
    }

    /**
     * 插入角色分配菜单记录
     *
     * @param item
     */
    public void addRoleMenu(SysRoleMenu item){
         writeSqlSession.insert(getWriteSql()+"addRoleMenu",item);
    }

    /**
     * 删除角色分配菜单记录
     *
     * @param id
     */
    public void deleteRoleMenu(Object id){
         writeSqlSession.delete(getWriteSql()+"deleteRoleMenu",id);
    }

    /**
     * 根据RoleId删除角色分配菜单记录
     *
     * @param roleId
     */
    public void deleteRoleMenuByRoleId(Object roleId){
        writeSqlSession.delete(getWriteSql()+"deleteRoleMenuByRoleId",roleId);
    }

    /**
     * 根据menuId删除角色分配菜单记录
     *
     * @param menuId
     */
    public void deleteRoleMenuByMenuId(Object menuId){
        writeSqlSession.delete(getWriteSql()+"deleteRoleMenuByMenuId",menuId);
    }

    /**
     * 插入角色分配账号记录
     *
     * @param item
     */
    public void addRoleMember(SysRoleMember item){
        writeSqlSession.insert(getWriteSql()+"addRoleMember",item);
    }

    /**
     * 删除角色分配账号记录
     *
     * @param id
     */
    public void deleteRoleMember(Object id){
        writeSqlSession.delete(getWriteSql()+"deleteRoleMember",id);
    }

    /**
     * 根据memberId删除角色分配人员的记录
     *
     */
    public void deleteRoleMemberByMemberId(Object memberId){
        writeSqlSession.delete(getWriteSql()+"deleteRoleMemberByMemberId",memberId);
    }

    /**
     * 根据roleId删除角色分配人员的记录
     *
     */
    public void deleteRoleMemberByRoleId(Object roleId){
        writeSqlSession.delete(getWriteSql()+"deleteRoleMemberByRoleId",roleId);
    }

    /**
     * 查询用户所拥有的id
     * @param sysRoleMember
     * @return
     */
    public List<SysRoleMember> memberRoleList(SysRoleMember sysRoleMember ){
        return readSqlSession.selectList(getReadSql()+"memberRoleList",sysRoleMember);
    }

}
